import requests
from bs4 import BeautifulSoup

if __name__ == "__main__":

    # 请求的URL
    url = 'http://data.sports.sohu.com/nba/nba_players_rank.php?order_by=points&spm=smpc.fb-nba-home.top-dc.2.1620824904040nf6byr7'
    # UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
    }
    respones = requests.get(url=url, headers=headers)
    respones.encoding = 'gbk'
    # 构造BeautifulSoup对象
    soup = BeautifulSoup(respones.text, "lxml")
    # 解析标签

    newslist = soup.select('.form > .blue > ul > li')
    fp = open("qui.txt", "w", encoding="utf-8")
    for i in newslist:
        # 文章标题
        title = i.string
        print(title, '爬取成功')

    list = soup.select('.table01 > tr')
    for j in list:
        fp.write(j.text)
        print(j.text, '爬取成功')

    fp.close()
